
// 类的实现
class Person {
  constructor(name, yearOfBirth, job) { //通过构造函数添加属性
    this.name = name;
    this.yearOfBirth = yearOfBirth;
    this.job = job;
  }
  calculateAge() { // 添加方法
    var age = new Date().getFullYear() - this.yearOfBirth;
    return age;
  }

  static greeting() {
    console.log('Hey there!');
  }
}
let john = new Person('John', 1999, 'teacher');
console.log(john.calculateAge()); // 调用方法


// 继承的实现
class Athlete extends Person {
  constructor(name, yearOfBirth, job, olympicGames, medals) {
    super(name, yearOfBirth, job);
    this.olympicGames = olympicGames;
    this.medals = medals;
  }

  wonMedal() {
    this.medals++;
    console.log(this.medals);
  }
}

const johnAthlete = new Athlete('John', 1990, 'swimmer', 3, 10);
console.log(johnAthlete.calculateAge());// 继承原型链上的方法
johnAthlete.wonMedal();

